//
//  HTTripDeatillCommentViewController.m
//  HeartTravel
//
//  Created by lanou on 15/10/30.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "HTTripDeatillCommentViewController.h"
#import "HTTripDeatillCommentTableViewCell.h"
#import "PKRequestManager.h"
#import "HTTripSomeoneCommentModel.h"
#import "HTTripDeatillSomeoneCommentView.h"
#import "UIImageView+WebCache.h"
#define CommentheaderURL @"http://api.daizhe.cn/common/comment?comment_type=9&relate_id="

#define footerURL @"&ac=list&device_type=2&cur_version=2.3.5.1&device_code=77FEFD37-68DD-413D-8097-32017A5C6634&device_token=21093eff1a82bf7778421dddfcf93b2e&dz_token=&dz_uid=&uid="

@interface HTTripDeatillCommentViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HTTripSomeoneCommentModel *someOneCommentMD;
@property (nonatomic, strong) NSMutableArray *someOneArr;
@end

@implementation HTTripDeatillCommentViewController

- (NSMutableArray *)someOneArr
{
    if (!_someOneArr) {
        _someOneArr = [NSMutableArray array];
    }
    return _someOneArr;
}

- (void)requestData
{
    NSString *str = [[CommentheaderURL stringByAppendingString:_commentModel.status_id]stringByAppendingString:footerURL];
    
    [PKRequestManager requestWithType:GET urlString:str parDic:nil finish:^(NSData *data) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) error:nil];
        
        NSArray *arr = dic[@"responseData"][@"list"];
        for (NSDictionary *dic2 in arr) {
            
            _someOneCommentMD = [[HTTripSomeoneCommentModel alloc]init];
            
            [_someOneCommentMD setValuesForKeysWithDictionary:dic2];
            
            [self.someOneArr addObject:_someOneCommentMD];
        }
        [self.tableView reloadData];
        
    } error:^(NSError *error) {
        NSLog(@"个人评论详情请求失败%@",error);
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestData];
    // Do any additional setup after loading the view.
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,70, SCREEN_WIDTH, SCREEN_HEIGHT - 80) style:(UITableViewStyleGrouped)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.rowHeight = 100;
    [self.view addSubview:_tableView];
    
    //表头
    [self headerView];

    //设置返回按钮
    UIButton *returnButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    returnButton.frame = CGRectMake(10, 15, 20, 20);
    [returnButton setImage:[UIImage imageNamed:@"return"] forState:(UIControlStateNormal)];
    
    [returnButton addTarget:self action:@selector(doreturn) forControlEvents:(UIControlEventTouchUpInside)];
    [self.topView addSubview:returnButton];
    
    
    
    //与nib文件相关联
    [_tableView registerNib:[UINib nibWithNibName:@"HTTripDeatillCommentTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"reuser"];
}

//表头
- (void)headerView
{
    HTTripDeatillSomeoneCommentView *someoneView = [[HTTripDeatillSomeoneCommentView alloc]init];
    someoneView.deattillCommentMD = _commentModel;
        _tableView.tableHeaderView = someoneView;
}

//返回上一个界面
- (void)doreturn
{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.someOneArr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"reuser";
    HTTripDeatillCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str forIndexPath:indexPath];
    cell.someoneMD = _someOneArr[indexPath.row];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
